package com.wechat.file.response;

import com.wechat.file.request.CheckFileRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Set;

/**
 * 文件检查响应
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CheckFileResponse {
    
    /**
     * 检查状态: EXIST(文件已存在-秒传), PARTIAL(部分上传-断点续传), NEW(需要新上传)
     */
    private String status;
    
    /**
     * 文件ID (秒传时返回)
     */
    private String fileId;
    
    /**
     * 缺失的分片编号列表 (断点续传时返回)
     */
    private Set<Integer> missingChunks;

    /**
     * 下载地址 (秒传时返回)
     */
    private String downloadUrl;

    private Integer totalChunks;

    public static CheckFileResponse buildExistResponse(String fileId, String downloadUrl) {
        return CheckFileResponse.builder()
                .status("EXIST")
                .fileId(fileId)
                .downloadUrl(downloadUrl).build();
    }

    public static CheckFileResponse buildPartialResponse(Set<Integer> missingChunks, int totalChunks) {
        return CheckFileResponse.builder()
                .status("PARTIAL")
                .missingChunks(missingChunks)
                .totalChunks(totalChunks)
                .build();
    }

    public static CheckFileResponse buildInitUploadResponse() {
        return CheckFileResponse.builder()
                .status("INIT")
                .build();
    }
}